package com.zyd.blog.personal.service.impl;

import com.zyd.blog.persistence.mapper.UserCollectionMapper;
import com.zyd.blog.personal.service.UserCollectionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * 用户收藏信息业务逻辑层
 * @author mfy
 */
@Service
public class UserCollectionServiceImpl implements UserCollectionService {

    @Resource
    private UserCollectionMapper userCollectionMapper;

    @Override
    public Boolean isHaveCollection(Long id,Long userId, Long productionId, String status){
        Map<String,Object> condition = new HashMap<>(16);
        condition.put("id",id);
        condition.put("userId",userId);
        condition.put("productionId",productionId);
        condition.put("status",status);
        List<Map<String,Object>> collections = userCollectionMapper.queryUserCollectionByCondition(condition);
        return collections != null && collections.size() != 0;
    }

    @Override
    public List<Map<String,Object>> getCollectionInfo(Long userId, Long productionId, String status){
        Map<String,Object> condition = new HashMap<>(16);
        condition.put("userId",userId);
        condition.put("productionId",productionId);
        condition.put("status",status);
        List<Map<String,Object>> collections = userCollectionMapper.queryUserCollectionByCondition(condition);
        if(collections == null || collections.size() == 0){
            return new ArrayList<>();
        }
        return collections;
    }

    @Override
    public int addCollection(Long userId,Long productionId){
        Map<String,Object> condition = new HashMap<>(16);
        condition.put("userId",userId);
        condition.put("productionId",productionId);
        condition.put("updateTime",(new Date()).getTime());
        condition.put("addTime",(new Date()).getTime());
        return userCollectionMapper.addUserCollection(condition);
    }

    @Override
    public int updateCollection(Long userId,Long productionId,String status){
        Map<String,Object> condition = new HashMap<>(16);
        condition.put("userId",userId);
        condition.put("productionId",productionId);
        condition.put("status",status);
        condition.put("updateTime",(new Date()).getTime());
        return userCollectionMapper.updateUserCollection(condition);
    }

}
